<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="项目名称" prop="xmName">
        <el-input v-model="queryParams.xmName" placeholder="请输入项目名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="企业名称" prop="qyName">
        <el-input v-model="queryParams.qyName" placeholder="请输入企业名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['guarantee:agreement:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="agreementList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" type="index" prop="id">
        <template slot-scope="scope">
          <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="业务员" align="center" prop="userName" />
      <el-table-column label="状态" align="center">
        <template slot-scope="scope">
          <span>{{ statusDict[scope.row.status] }}</span>
        </template>
      </el-table-column>
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="出函类型" align="center" prop="xmChType" />
      <el-table-column label="项目名称" align="center" prop="xmName" />
      <el-table-column label="标段" align="center" prop="xmNameLot" />
      <el-table-column label="保函类型" align="center" prop="xmBhType" />
      <el-table-column label="中标金额" align="center" prop="xmMoney" />
      <el-table-column label="企业名称" align="center" prop="qyName" />
      <el-table-column label="返润" align="center" prop="ywFanMoney" />
      <el-table-column label="扣税" align="center" prop="ywTaxMoney" />
      <el-table-column label="业绩" align="center" prop="ywYeji" />
      <el-table-column label="出函日期" align="center" prop="bhDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.bhDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-tickets" @click="openDetail(scope.row)"
            v-hasPermi="['guarantee:bidding:detail']">详情</el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <!-- 详情弹窗 -->
    <agreement-detail :form="detailform" :detailOpen="detailOpen" @changeDialog="changeDialog" />
  </div>
</template>

<script>
import {
  historyList,
  getAgreement
} from "@/api/guarantee/agreement";
import { pcTextArr } from "element-china-area-data";
import AgreementDetail from '@/views/guarantee/detail/agreement'

export default {
  name: "Agreement",
  components: {
    AgreementDetail
  },
  data() {
    return {
      statusDict: {
        '0': '草稿',
        '2': '主管待审核',
        '4': '业务总待审核',
        '6': '财务待确认',
        '8': '运营待送审',
        '10': '运营待提交',
        '12': '财务核算成本',
        '14': '完成',
        '-1': ' 驳回'
      },
      // 合作方费用显示
      fkHzShow: false,
      // 保函比例显示
      xmBhblshow: false,
      // 省市数据
      areaData: pcTextArr,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 履约保函表格数据
      agreementList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        xmChDjuser: null,
        xmName: null,
        qyName: null
      },
      // 表单参数
      form: {},
      // 详情弹窗
      detailOpen: false,
      detailform: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 有无合作方费用修改 */
    fkHzChange(val) {
      if (val === '有') {
        this.fkHzShow = true
      } else {
        this.fkHzShow = false
      }
    },
    /** 保函类型修改 */
    typeChange(val) {
      if (val === '履约' || val === '预付款') {
        this.xmBhblshow = true
      } else {
        this.xmBhblshow = false
      }
    },
    /** 删除标段 */
    deleteLot(index) {
      this.form.xmNameLot.splice(lvyue, 1)
    },
    /** 添加标段 */
    addLot() {
      this.form.xmNameLot.push('')
    },
    /** 企业省市修改 */
    handleQyAreaChange(value) {
      this.form.qySheng = value[0]
      this.form.qyShi = value[1]
    },
    /** 省市修改 */
    handleAreaChange(value) {
      this.form.xmSheng = value[0]
      this.form.xmShi = value[1]
    },
    /** 查询履约保函列表 */
    getList() {
      this.loading = true;
      historyList(this.queryParams).then(response => {
        this.agreementList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        wxx: null,
        status: null,
        xmChType: null,
        xmChDjuser: null,
        xmBhType: null,
        xmSyName: null,
        xmSyType: null,
        xmName: null,
        xmNameLot: [''],
        xmShengAndShi: null,
        xmSheng: null,
        xmShi: null,
        xmAddress: null,
        xmType: null,
        xmSpecial: null,
        xmSpecialName: null,
        xmDate: null,
        xmMoney: null,
        xmBhProportion: null,
        xmGongqi: null,
        xmArticleUrl: null,
        xmZbUrl: null,
        xmContractUrl: null,
        xmSyUrl: null,
        xmXmmcyjUrl: null,
        xmBhyjUrl: null,
        xmGqyjUrl: null,
        qyName: null,
        qyShengAndShi: null,
        qySheng: null,
        qyShi: null,
        qyAddress: null,
        qyZcMoney: null,
        qyClDate: null,
        qyType: null,
        qyZizhi: null,
        qySpecial: null,
        qyFpType: null,
        qyKpName: null,
        qyKpNum: null,
        qyKpPhone: null,
        qyKpAddress: null,
        qyKpBank: null,
        qyKpBankNum: null,
        qyKpSendAdress: null,
        bhMoney: null,
        bhGeshi: null,
        bhGeshiUrl: null,
        bhRemark: null,
        fkMoney: null,
        fkType: null,
        fkUrl: null,
        fkHzMoney: null,
        fkHzUrl: null,
        fkHzType: null,
        fkShouyi: null,
        fkFanrun: null,
        yyAcceptanceOpinion: null,
        yyPrice: null,
        yySupplyUrl: null,
        yySpecialRemark: null,
        yyContractData: null,
        yyContractHg: null,
        yySupplyRemark: null,
        yyFandanbaoqianshu: null,
        yyYoujidanhao: null,
        ywTotalMoney: null,
        bankMoney: null,
        bankAccount: null,
        bankSf: null,
        bankMoney2: null,
        bankAccount2: null,
        bankSf2: null,
        ywFanMoney: null,
        ywTaxMoney: null,
        ywYeji: null,
        sfKp: null,
        bhDate: null,
        mailNum: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");

    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },

    /** 详情按钮操作 */
    openDetail(row) {
      const id = row.id || this.ids
      getAgreement(id).then(response => {
        this.detailform = response.data;
        if (this.detailform.isBulu === '有') {
          this.detailform.fkHzShow = true
        } else {
          this.detailform.fkHzShow = false
        }
        if (this.detailform.xmBhType === '履约' || this.detailform.isBulu === '预付款') {
          this.detailform.xmBhblshow = true
        } else {
          this.detailform.xmBhblshow = false
        }
        this.detailform.xmShengAndShi = [this.detailform.xmSheng, this.detailform.xmShi]
        this.detailform.qyShengAndShi = [this.detailform.qySheng, this.detailform.qyShi]
        this.detailOpen = true;
      });
    },
    changeDialog(val) {
      this.detailOpen = val;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        console.log(valid, 'valid')
        if (valid) {
          console.log(this.form, 'this.form')
          if (this.form.id != null) {
            checkSave(this.form).then(response => {
              this.$modal.msgSuccess("审核成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('guarantee/agreement/export', {
        ...this.queryParams
      }, `agreement_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style lang="scss" scoped>
.my_select {
  width: 204px;
}

.my_picker {
  width: 204px;
}

.lotInput {
  width: 150px;
  margin-right: 10px;
}

.bd_box {
  display: flex;
  flex-wrap: wrap;
}

.disable_upload ::v-deep .el-upload--picture-card,
.disable_upload ::v-deep .upload-file-uploader,
.disable_upload::v-deep .ele-upload-list__item-content-action {
  display: none
}

.label_txt {
  width: 204px
}
</style>
